package com.javaapi.designmode;
interface DownloadListenter{
	void downLoading(int progress);
	void downLoaded();
}
class DownloadUtil{
	public DownloadUtil(){
	}
	private static DownloadUtil downloadUtil=null;
	public static synchronized  DownloadUtil getInstance(){
		if (downloadUtil==null) {
			downloadUtil=new DownloadUtil();
		}
		return downloadUtil;
	}
	private int progress=0;
	private boolean isDownloading=true;
	
	public void download(DownloadListenter listenter){
		while (isDownloading) {
			listenter.downLoading(progress);
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			progress+=10;
			if (progress>=100) {
				isDownloading=false;
			}
		}
		listenter.downLoaded();
	}
}

public class DownUI {
	public static void main(String[] args) {
		DownloadUtil downloadUtil=DownloadUtil.getInstance();
		downloadUtil.download(myDownloadListenter);
	}

	private static  DownloadListenter myDownloadListenter=new DownloadListenter() {
		
		@Override
		public void downLoading(int progress) {
			System.out.println(progress);
		}
		
		@Override
		public void downLoaded() {
			System.out.println("downLoaded");
		}
	};
	
}
